using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace SimpleFramework
{
    public class CameraFollow2DState : CameraState
    {
        private Transform m_CameraT;
        private Transform m_TargetT;
        private Rect m_Region;

        public CameraFollow2DState(CameraContext context) : base(context)
        {
        }

        public override void OnEnter()
        {
            var camera = m_Context.camera;
            camera.orthographic = true;
            camera.orthographicSize = m_Context.orthographicSize;

            m_CameraT = camera.transform;
            m_TargetT = m_Context.target;
            m_Region = m_Context.region;
        }

        public override void OnUpdate()
        {
            var position = m_TargetT.position;
            position.z = m_Context.orthographicDistnce;
            position.x = Mathf.Clamp(position.x, m_Region.xMin, m_Region.xMax);
            position.y = Mathf.Clamp(position.y, m_Region.yMin, m_Region.yMax);
            m_CameraT.position = position;
        }

        public override void OnExit()
        {

        }
    }
}